<?php
include("../models/entities/class.AccountEntity.php");
@session_start();
if(isset($_SESSION["Username"]))
{
    include("../models/webconfig.php");
    include("../models/class.connection.php");
    include("../models/entities/class.CategoryEntity.php");
    include("../models/repositories/class.CategoryRepository.php");
    include("../models/entities/class.SectionEntity.php");
    include("../models/repositories/class.SectionRepository.php");
    
    include("../models/repositories/class.GroupAuthorityRepository.php");
    if(isset($_SESSION['Account'])){
        $groupAuthorityRepository = new GroupAuthorityRepository();
        $account = $_SESSION['Account'];
        if(!$groupAuthorityRepository->CheckExistGroupAuthority($account->GroupID_i, 5))
            header("location:NoAccess.php");
    }
    else
    {
        header("location:NoAccess.php");
    }
    
    $sectionRepository = new SectionRepository();
    $categoryRepository = new CategoryRepository();
    $results = $categoryRepository->GetAll();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Category Manager</title>
<link href="../content/Layout.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="../content/ui-lightness/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" media="screen"/>
<script type="text/javascript" src="../scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript" src="../scripts/search_backend.js"></script>
<script type="text/javascript" src="../scripts/admincategory.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var str = location.href.toLowerCase();

        $('ul#mainNav li a').each(function () {
            if (str.indexOf($(this).attr("href").toLowerCase()) > -1)
             $(this).addClass("active");
        });

        $('ul#sideNav li a').each(function () {
            if (str.indexOf($(this).attr("href").toLowerCase()) > -1)
            $(this).addClass("active");
        });
        
        CategoryManager.init();
    });
</script>
</head>

<body>
    <div id="format">
        <div id="wrapper">
        	<!--Ph?n main menu-->
			<?php
				include("../includes/backend_mainnav.php");
			?>
		
            <div id="containerHolder">
                <div id="container" style="color: #646464;">
                	<!--Ph?n main content vi?t t?i dây-->
                    <h3>Danh sách category</h3>
                    <div class="clear"></div>
                    <div style="float: right; margin-right:20px; font-weight: bold;"><a href="CreateCategory.php">Thêm category</a></div>
                    <div class="clear"></div>
                    <div class="data" id="categoryContent" style="background: none; margin-top: 20px; text-align: center; width: 100%; min-height: 100px;">
                        <div class="loading"></div>
                        <table>
                            <tr>
                                <td>ID</td>
                                <td>Tên</td>
                                <td>Section</td>
                                <td></td>
                                <td></td>
                            </tr>
                            <?php
                                for($i = 0; $i < count($results); $i++){
                            ?>
                            <tr>
                                <td>
                                    <?php echo $results[$i]->ID_i; ?>
                                </td>
                                <td><a href="EditCategory.php?categoryID=<?php echo $results[$i]->ID_i; ?>"><?php echo $results[$i]->Name_s; ?></a></td>
                                <td>
                                    <?php 
                                        echo $sectionRepository->GetSection($results[$i]->SectionID_i)->Name_s;
                                    ?>
                                </td>
                                <td><a href="EditCategory.php?categoryID=<?php echo $results[$i]->ID_i; ?>">Sửa</a></td>
                                <td><a href="#" onclick="return false;" class="deleteCategory" categoryID="<?php echo $results[$i]->ID_i; ?>" categoryName="<?php echo $results[$i]->Name_s; ?>">Xóa</a></td>
                            </tr>
                            <?php
                                }
                            ?>
                        </table>
                    </div>
                </div>
                <!-- // #main -->
            </div>
            <div id="dialog" title="Section"></div>
            <!-- // #container -->
            
            <!--Ph?n footer c?a trang-->
            <?php
            include("../includes/backend_footer.php");
            ?>
        </div>
        </div>
</body>

</html>
<?php
}
else
{
    header("location:../views/Admin_login.php?logout=TRUE");
}
?>